package repo

import (
	"context"
	"gitee.com/ZLX0326/gin_learn/bingweb/internal/domain"
	"gitee.com/ZLX0326/gin_learn/bingweb/internal/repo/dao"
)

var UserNotFoundErr = dao.UserNotFoundErr

type UserRepo struct {
	Dao *dao.UserDao
}

func (repo *UserRepo) Create(ctx context.Context, u domain.User) error {
	err := repo.Dao.Insert(ctx, dao.User{
		Email:    u.Email,
		Password: u.Passwd,
	})
	if err != nil {
		return err
	}
	return nil
}
func (repo *UserRepo) FindByEmail(ctx context.Context, email string) (*domain.User, error) {
	u, err := repo.Dao.SelectByEmail(ctx, email)
	if err != nil {
		return nil, err
	}
	return &domain.User{
		Id:     u.Id,
		Email:  u.Email,
		Passwd: u.Password,
	}, nil
}
